Skip to content

feat: add market order support (estimated price + reconciliation)#432

Merged
MDUYN merged 1 commit into
devfrom
feature/market-order-support
Apr 22, 2026
Merged

feat: add market order support (estimated price + reconciliation)#432
MDUYN merged 1 commit into
devfrom
feature/market-order-support

Conversation

@MDUYN
Copy link
Copy Markdown
Collaborator

@MDUYN MDUYN commented Apr 20, 2026

Summary

Adds market order support to the framework. Market orders execute at the best available price — in backtesting this means the Open price of the next candle (+ optional slippage via TradingCost).

Changes

Core implementation:

  • Add MARKET to OrderType enum
  • Add estimated_price property to Order model (stored in metadata, no DB migration needed)
  • Add create_market_order(), create_market_buy_order(), create_market_sell_order() to Context and TradingStrategy
  • Add validate_market_order() to OrderService (balance/position checks using estimated price)

Backtesting:

  • Market orders fill at the Open price of the first candle after order.updated_at
  • Slippage applied via TradingCost when configured
  • Portfolio automatically reconciled: delta between estimated and actual fill price adjusted in unallocated balance and position

Live trading:

  • CCXT executor calls createMarketBuyOrder() / createMarketSellOrder() (no price param)

Tests:

  • 14 new tests covering: enum, estimated_price model, order creation, fill at open price, slippage, portfolio reconciliation, validation

Docs:

  • Updated orders.md with market order API, parameters, and examples (DCA, Grid, Trailing Stop)
  • Updated strategies.md with market order methods in the reference section

Closes #430

- Add MARKET to OrderType enum
- Add estimated_price property to Order model (stored in metadata)
- Add create_market_order(), create_market_buy_order(), create_market_sell_order() to Context and TradingStrategy
- Add validate_market_order() to OrderService
- Market orders fill at Open price of next candle in backtesting
- Apply slippage via TradingCost when configured
- Reconcile portfolio delta between estimated and actual fill price
- Add CCXT market order execution (createMarketBuyOrder/createMarketSellOrder)
- Add 14 tests covering enum, model, creation, fill, slippage, reconciliation, validation
- Update orders.md and strategies.md documentation

Closes #430
@MDUYN MDUYN merged commit 7950c99 into dev Apr 22, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant